﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
    public class Ctbl_Download:IData<tbl_Download>
    {
        public Ctbl_Download() { }
        public Ctbl_Download(String myconnecString)
            : base(myconnecString)
        {
 
        }

        public override List<tbl_Download> GetAll(tbl_Download item)
        {
            throw new NotImplementedException();
        }

        public override tbl_Download GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.Id == Convert.ToInt32(id));
        }

        public override tbl_Download GetItem(System.Data.IDataReader dr)
        {
            tbl_Download obj = new tbl_Download();
            obj.AddedDate = Convert.ToDateTime(dr[tbl_Download.c_addedDate]);
            obj.Description = Convert.ToString(dr[tbl_Download.c_Description]);
            obj.Id = Convert.ToInt32(dr[tbl_Download.c_id]);
            obj.Image = Convert.ToString(dr[tbl_Download.c_Image]);
            obj.IsActive = Convert.ToInt32(dr[tbl_Download.c_isActive]);
            obj.OrderId = Convert.ToInt32(dr[tbl_Download.c_orderId]);
            obj.Path = Convert.ToString(dr[tbl_Download.c_Path]);
            obj.Title = Convert.ToString(dr[tbl_Download.c_Title]);
            obj.GroupID = Convert.ToInt32(dr[tbl_Download.c_GroupID]);
            obj.Mota = dr[tbl_Download.c_Mota].ToString();
            return obj;
        }

        public override List<tbl_Download> GetAll()
        {
            String strSQL = "select * from " + tbl_Download.b_tbl_Download + strAsc;
            return GetAll(strSQL, CommandType.Text);
        }

        protected override int InsertOnSubmit(tbl_Download item, int t)
        {
            int id = -1;
            id = connec.ExecuteNonQuery("RCUDDownload", CommandType.StoredProcedure, new SqlParameter("@flag", t),
                new SqlParameter("@" + tbl_Download.c_addedDate, item.AddedDate), new SqlParameter("@" + tbl_Download.c_Description, item.Description),
                new SqlParameter("@" + tbl_Download.c_id, item.Id), new SqlParameter("@" + tbl_Download.c_Image, item.Image),
                new SqlParameter("@" + tbl_Download.c_isActive, item.IsActive), new SqlParameter("@" + tbl_Download.c_orderId, item.OrderId),
                new SqlParameter("@" + tbl_Download.c_Path, item.Path), new SqlParameter("@" + tbl_Download.c_Title, item.Title));

            return id;
        }
    }
}
